home *** CD-ROM | disk | FTP | other *** search
/ Interactive Media Design Review 1999 / Interactive Media Design Review 1999.iso / pc / Demos / Herois / Codigo.Cst / 00020_Script_Texto Scroll por Sensibilidade < prev    next >
Text File  |  1999-03-19  |  6KB  |  203 lines

  1. property spr, mem
  2. property interessados
  3. property velMax, velMin, puloMax
  4. property linhaAtual, linhaMax
  5. property numLinhas
  6. property alturaLinha, linhasJanela
  7. property ultimoScroll, lastOut
  8. property areaSensivel
  9. property ligado, modificouCursor
  10. property numCursor
  11.  
  12. on getPropertyDescriptionList
  13.   set p_list = [ ¼
  14.     #alturaLinha: [ #comment: "Altura (em pixels) de cada linha (0 p/ nao alterar)", ¼
  15.                #format:  #integer,¼
  16.                #default: 16 ],¼
  17.     #velMax: [ #comment: "Velocidade maxima(pix/s)", ¼
  18.                #format:  #integer,¼
  19.                #default: 96 ],¼
  20.     #velMin: [ #comment: "Velocidade minima(pix/s)", ¼
  21.                #format:  #integer,¼
  22.                #default: 16 ],¼
  23.     #puloMax: [ #comment: "Maior pulo do scroll (em pixels)", ¼
  24.                #format:  #integer,¼
  25.                #default: 16 ],¼
  26.     #interessados: [ #comment: "Sprites que se interessam pelo scroll:", ¼
  27.                #format:   #list, ¼
  28.                #default: [] ],¼
  29.     #areaSensivel: [ #comment: "Area sensivel (em pixels)", ¼
  30.                #format:  #integer,¼
  31.                #default: 48 ]¼
  32.   ]
  33.   return p_list
  34. end
  35.  
  36. on beginSprite me
  37.   set spr = the spriteNum of me
  38.   set mem = the member of sprite spr
  39.   set linhaAtual = 0
  40.   set numLinhas = the lineCount of member mem
  41.   if alturaLinha = 0 then
  42.     set alturaLinha =  lineheight(mem, 1)
  43.   else
  44.     set the lineHeight of member mem to alturaLinha
  45.   end if
  46.   set linhasJanela = the height of sprite spr
  47.   set linhaMax = numLinhas
  48.   set linhaMax = numLinhas * alturaLinha - linhasJanela / 2
  49.   if linhaMax < 0 then set linhaMax = 0
  50.   set the scrollTop of member mem to 0
  51.   set ultimoScroll = the timer
  52.   set lastOut = true
  53.   --  set the visibility of sprite spr to false
  54.   --  set ligado = false
  55.   set modificouCursor = false
  56.   set numCursor = 1
  57. end
  58.  
  59. on cleanSprite me
  60.   set the visibility of sprite (the spriteNum of me) to true
  61. end 
  62.  
  63. on idleSprite me
  64.   global gMustUpdate
  65.   
  66.   --  if not ligado then
  67.   --    set the visibility of sprite spr to true
  68.   --    set ligado = true
  69.   --    set gMustUpdate = true
  70.   --  end if
  71.   if not the visible of sprite spr then return
  72.   
  73.   -- Verifica se mouse passa por cima do texto
  74.   global gCritico
  75.   if not rollOver(spr) or gCritico > 0 then
  76.     set lastOut = true
  77.     if modificouCursor then 
  78.       cursor -1
  79.       set modificouCursor = false
  80.     end if
  81.     return
  82.   end if
  83.   
  84.   
  85.   global gCritico, gMustUpdate
  86.   set y = the mouseV
  87.   
  88.   -- Calcula velocidade conforme posicao do mouse
  89.   set v = 0
  90.   set y = y - the locV of sprite spr
  91.   if (y < areaSensivel) then 
  92.     set v = -( (areaSensivel - y) * (velMax - velMin) / areaSensivel + velMin )
  93.   else 
  94.     set y = (the height of sprite spr) - y
  95.     if (y < areaSensivel) then
  96.       set v = (areaSensivel - y) * (velMax - velMin) / areaSensivel + velMin
  97.     end if
  98.   end if
  99.   if v = 0 then 
  100.     if not lastOut then set lastOut = true
  101.     if modificouCursor then 
  102.       cursor -1
  103.       set modificouCursor = false
  104.     end if
  105.     return
  106.   end if  
  107.   
  108.   -- Calcula delta de linhas
  109.   if lastOut then
  110.     set lastOut = false
  111.     set ultimoScroll = the timer
  112.     return
  113.   end if
  114.   set dl = (the timer - ultimoScroll) * v / 60
  115.   if dl > 0 and linhaAtual = linhaMax then set dl = 0
  116.   else if dl < 0 and linhaAtual = 0 then set dl = 0
  117.   
  118.   if dl = 0 then 
  119.     if modificouCursor then 
  120.       cursor -1
  121.       set modificouCursor = false
  122.     end if
  123.     return
  124.   end if
  125.   
  126.   if dl > 0 then 
  127.     cursor [the number of member ("CursorBaixo" & numCursor),¼
  128.             the number of member "CursorMask"]
  129.     set numCursor = 3 - numCursor
  130.     set modificouCursor = true
  131.     if dl > puloMax then 
  132.       set dl = puloMax
  133.     end if
  134.   else
  135.     cursor [the number of member ("CursorCima" & numCursor),¼
  136.             the number of member "CursorMask"]
  137.     set numCursor = 3 - numCursor
  138.     set modificouCursor = true
  139.     if dl < - puloMax then
  140.       set dl = - puloMax
  141.     end if
  142.   end if
  143.   set ultimoScroll = the timer
  144.   
  145.   -- Calcula nova linha
  146.   set l = linhaAtual + dl
  147.   if l < 0 then set l = 0
  148.   else if l > linhaMax then
  149.     set dl = dl + linhaMax
  150.     set l = linhaMax
  151.   end if
  152.   
  153.   if l <> linhaAtual then
  154.     set the scrollTop of member mem to l
  155.     set gMustUpdate = true
  156.     repeat with i = 1 to count(interessados)
  157.       sendSprite(getAt(interessados,i), #scrollLinha, l - linhaAtual)
  158.     end repeat
  159.     set linhaAtual = l
  160.   end if
  161. end
  162.  
  163. on mouseUp me
  164.   set y = the mouseV
  165.   set dl = 0
  166.   
  167.   -- Calcula velocidade conforme posicao do mouse
  168.   set y = y - the locV of sprite spr
  169.   if (y < areaSensivel and linhaAtual > 0) then 
  170.     puppetSound 2, "Warp1"
  171.     -- Scroll page down
  172.     set dl = - linhasJanela
  173.     -- termina if logo acima
  174.   else 
  175.     set y = (the height of sprite spr) - y
  176.     if (y < areaSensivel and linhaAtual < linhaMax) then
  177.       puppetSound 2, "Warp2"
  178.       -- Scroll page up
  179.       set dl = + linhasJanela
  180.     end if
  181.   end if
  182.   
  183.   if dl = 0 then return 
  184.   
  185.   -- Calcula nova linha
  186.   set l = linhaAtual + dl
  187.   if l < 0 then set l = 0
  188.   else if l > linhaMax then
  189.     set l = linhaMax
  190.   end if
  191.   
  192.   if l <> linhaAtual then
  193.     set the scrollTop of member mem to l
  194.     repeat with i = 1 to count(interessados)
  195.       sendSprite(getAt(interessados,i), #scrollLinha, l - linhaAtual)
  196.     end repeat
  197.     set linhaAtual = l
  198.   end if
  199.   
  200.   updateStage
  201.   
  202.   stopEvent
  203. end